﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddRelationPage.aspx.cs" Inherits="Easy.Web.Pages.EntityPages.AddRelationPage" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <link href="/_css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="/_css/common.css" rel="stylesheet" type="text/css" /> 
    <link rel="stylesheet" type="text/css" href="/_css/iconfont.css" />
    <script src="/_js/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script src="/_js/bootstrap.min.js" type="text/javascript"></script>
    <script src="/_js/json2.js" type="text/javascript"></script>
    <script  type="text/javascript">
        $(document).ready(function () {
            GetEntityList();
        });

        function GetEntityList() {
            $.ajax({
                url: "/Service/Entity/GetEntityList.ashx",
                async: false,
                type: "post",
                dataType: "json",
                data: {
            },
            success: function (data, textStatus) {

                var SMShtml = "";

                for (var i = 0; i < data.length; i++) {
                    var item = data[i];



                    SMShtml += "<option value='" + item.EntityName + "'>" + item.EntityDisplayName + "</option>";


                }



                $("#RelationEntity").html(SMShtml);
                RelationEntity_change();
            },
            error: function (data, textStatus) {
                alert("ajax错误");

            }

        });

    }


    function addReletion(type) {
            var add = {};
            add["EntityName1"] = $("#EntityName").val();
            add["EntityName2"] = $("#RelationEntity").val();
            add["RelationName"] = $("#RelationName").val();
            

            $.ajax({
                url: "/Service/Entity/AddReletion.ashx",
                async: false,
                type: "post",
                dataType: "JSON",
                data: { "addReletion": JSON.stringify(add)
                },
                success: function (data, textStatus) {
                    if (data.Result == "0") {
                        if (type == 1) {
                            window.location = "AttributeListPage.aspx?Id=" + $("#entityid").val();
                        } else if (type == 2) {
                            window.location = "AddRelationPage.aspx?Id=" + $("#entityid").val();
                        }
                    }
                    else {
                        alert(data.Remark);
                    }

                },
                error: function (data, textStatus) {
                    alert("错误");

                }

            });
        }
        function btn_return() {
            window.location = "AttributeListPage.aspx?Id=" + $("#entityid").val();

        }


        function RelationEntity_change() {
            $("#RelationName").val($("#EntityName").val() + "_" + $("#RelationEntity").val());
        }
    </script>
    <style>
        .page-header{margin:15px;}
        .page-header+.btn-primary{margin:0px 15px 10px 5px;}
        .panel-heading{padding:3px 15px;height:40px;line-height:34px;}
    </style>
</head>
<body>
    <form id="form1" runat="server" >
    <input id="entityid" type="hidden" value="<%=_EntityId %>" />
    <input id="EntityName" type="hidden" value="<%=EntityName %>" />
    <div class="">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">
                    新建关系</h1>
                       <button type='button' style="float: right" id='Button1' class='btn btn-primary ng-binding'
                            onclick="btn_return();">
                            取消</button>
            </div>
            <!-- /.col-lg-12 -->
        </div>
        <!-- /.row -->
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <!-- /.panel-heading -->
                    <div class="panel-body">
                        <div class="form-group">
                            <label for="RelationEntity">
                                主实体</label>
                            <input type="text" value="<%=EntityDisplayName %>"  class="form-control"  disabled="disabled"/>
                        </div>  
                        <div class="form-group">
                            <label for="RelationEntity">
                                关联实体</label>
                             <select class="form-control" id="RelationEntity" onchange="RelationEntity_change()">
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="RelationName">
                               关系名称</label>
                            <div class="input-group">
                                <div class="input-group-addon">
                                    <%=Prefix%>_</div>
                                <input type="text" class="form-control" id="RelationName" />
                               
                            </div>
                        </div>
                       
                       
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="button" class="btn btn-primary ng-binding" onclick="addReletion(1);">
                                    保存并关闭</button>
                                    <button type="button" class="btn btn-primary ng-binding" onclick="addReletion(2);">
                                    保存并新建</button>
                            </div>
                        </div>
                    </div>
                    <!-- /.panel-body -->
                </div>
                <!-- /.panel -->
            </div>
        </div>
    </div>
    </form>
</body>
</html>
